<?php

// //////////////////////////////////////////////////
// SMTP - PHP SMTP class
//
// Version 1.02
//
// Define an SMTP class that can be used to connect
// and communicate with any SMTP server. It implements
// all the SMTP functions defined in RFC821 except TURN.
//
// Author: Chris Ryan
//
// License: LGPL, see LICENSE
// //////////////////////////////////////////////////
class desktop_email_smtp {

    private $_adapter = null;

    public function desktop_email_smtp($app) {
        // $this->_adapter = kernel::single("desktop_email_smtp_curl");
        if (constant("ECAE_MODE")) {
            $this->_adapter = kernel::single("desktop_email_smtp_ecae");
        } else if (function_exists("fsockopen")) {
            $this->_adapter = kernel::single("desktop_email_smtp_fsockopen");
        } else if (function_exists("curl_init")) {
            $this->_adapter = kernel::single("desktop_email_smtp_curl");
        } else {
            die("smtp no support!");
        }
    }

    public function setSubject($subject) {
        $this->_adapter->subject = $subject;
    }

    public function setBody($body) {
        $this->_adapter->body = $body;
    }

    function Connect($host, $port = 0, $tval = 30, $ssl = '') {
        return $this->_adapter->Connect($host, $port, $tval, array(), $ssl);
    }

    function Authenticate($username, $password) {
        return $this->_adapter->Authenticate($username, $password);
    }

    function Connected() {
        return $this->_adapter->Connected();
    }

    function Close() {
        return $this->_adapter->Connected();
    }

    function Data($msg_data) {
        return $this->_adapter->Data($msg_data);
    }

    function Expand($name) {
        return $this->_adapter->Expand($name);
    }

    function Hello($host = "") {
        return $this->_adapter->Hello($host);
    }

    function SendHello($hello, $host) {
        return $this->_adapter->SendHello($hello, $host);
    }

    function Help($keyword = "") {
        return $this->_adapter->Help($keyword);
    }

    function Mail($from) {
        return $this->_adapter->Mail($from);
    }

    function Noop() {
        return $this->_adapter->Noop();
    }

    function Quit($close_on_error = true) {
        return $this->_adapter->Quit($close_on_error);
    }

    function Recipient($to) {
        return $this->_adapter->Recipient($to);
    }

    function Reset() {
        return $this->_adapter->Reset();
    }

    function Send($from) {
        return $this->_adapter->Send($from);
    }

    function SendAndMail($from) {
        return $this->_adapter->SendAndMail($from);
    }

    function SendOrMail($from) {
        return $this->_adapter->SendOrMail($from);
    }

    function Turn() {
        return $this->_adapter->Turn();
    }

    function Verify($name) {
        return $this->_adapter->Verify($name);
    }

    function getError() {
        return $this->_adapter->error;
    }
} // end the class
